package com.bb.flow.api.entries;

import com.bb.flow.config.AbstractConfigNode;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @author bigbeard
 * 流程启动时回调通知信息
 */
public class NotifyFlowStartInfo extends BaseFlowNotify {

    /**
     * 流程节点
     */
    private final List<NodeNotifyInfo> flowNodes = new ArrayList<>();
    /**
     * 流程上下文
     */
    private final Object flowContext;

    /**
     * 父流程信息
     */
    private final NotifyParentFlowInfo parentFlowInfo;

    /**
     * @param flowTemplateName 流程模版名称
     * @param flowInstanceName 流程实例名称
     * @param flowNodes        流程节点
     * @param flowContext      流程上下文
     * @param parentFlowInfo   父流程信息
     */
    public NotifyFlowStartInfo(
            String flowTemplateName, String flowInstanceName, Map<String, AbstractConfigNode> flowNodes,
            NotifyParentFlowInfo parentFlowInfo, Object flowContext) {
        this.flowContext = flowContext;
        this.setFlowInstanceName(flowInstanceName);
        this.setFlowTemplateName(flowTemplateName);
        if (flowNodes != null) {
            flowNodes.values().forEach(x -> this.flowNodes
                    .add(new NodeNotifyInfo()
                            .setNodeType(x.getNodeType().toString())
                            .setNodeKey(x.getNodeKey())
                    ));
        }
        this.parentFlowInfo = parentFlowInfo;
    }

    /**
     * 获取流程上下文信息
     *
     * @return 流程上下文
     */
    public Object getFlowContext() {
        return flowContext;
    }

    /**
     * 父流程信息
     *
     * @return 父流程
     */
    public NotifyParentFlowInfo getParentFlowInfo() {
        return parentFlowInfo;
    }

    /**
     * 流程节点
     *
     * @return 流程节点
     */
    public List<NodeNotifyInfo> getFlowNodes() {
        return flowNodes;
    }

}
